<?php


    class ArtigoController extends Zend_Controller_Action
    {
        private $artigo;
        
         public function preDispatch()
        {            
            require_once APPLICATION_PATH . '/models/Artigo.php';
            $this->artigo = new Artigo();
                      
        }
        
        public function createAction()
        {
             $registry = Zend_Registry::getInstance();
             $registry->set('tela','createArticle');

            require_once APPLICATION_PATH . '/forms/Forms_CriarArtigo.php';
            $form = new Forms_CriarArtigo();
            $form->setAction($this->_helper->url('reciveform'));
            $form->showForm('create','/artigo/reciveform');
        }
        
        public function reciveformAction()
        {
            require_once APPLICATION_PATH . '/forms/Forms_CriarArtigo.php';
            $form = new Forms_CriarArtigo();

            if($this->getRequest()->isPost())
            {
                $data = $this->_request->getPost();

                if($form->isValid($data))
                {
                   $usuario = new Zend_Session_Namespace('usuario');
                   $currentNod = new Zend_Session_Namespace('currentNod');
                 
                  $bibliograpy = explode(',', $_POST['bibliograpy']);                  
                  $parameters = array('editability' => $_POST['editability'],
                                        'title' => $_POST['title'],
                                        'content' => $_POST['editor'],
                                        'bibliograpy' => $bibliograpy,
                                        'eMailOwner' => $usuario->eMail,
                                        'nameNode' => $currentNod->name
                                            );
                    
                 
                 $this->artigo->create($parameters);
                 $this->_redirect('/nodo/into');
                }
                else
                {
                     $this->view->message = 'Dados Invalidos';
                }
            }
        }
        
        public function intoAction()
        {
            $registry = Zend_Registry::getInstance();
             $registry->set('tela','intoArticle');
            /*THE FORM HEADER
             * 
             * 'id' => $article['articleId'],
             'ownerId' => $article['userId'],
              'title' => $article['title'],
              'content' => $article['content'],
              'editability' => $article['editability'],
              'aprovedData' => $article['aprovedData']
             * 
             * 
             */
             
             
             $parameters = array( 'id' => $_POST['id'],
                                  'ownerId' => $_POST['ownerId'],
                                  'title' => $_POST['title'],
                                  'content' => $_POST['content']
                                );
             $this->artigo->showArticle($parameters); 
        
        }
        

    }

?>
